#include <stdlib.h>
#include <stdio.h>

int main()
{
    const char filename[] = "/tmp/log.txt";
    FILE* file = fopen(filename, "w+");

    if (!file)
    {
        fprintf(stderr, "failed to open file\n");
        exit(2);
    }

    fputs("this is test line", file);

    fseek(file, 0, SEEK_SET);

    const int sz = 1024;
    char buf[sz];
    char* line = fgets(buf, sz, file);

    if (line)
    {
        printf("line: \"%s\"\nbuf: \"%s\"\n", line, buf);
    }
    else if(feof(file))
    {
        printf("EOF found\n");
    }

    fclose(file);

    return 0;
}
